//
//  DataAnalyzer.h
//  MarketDataAnalyzer
//
//  Created by jiro on 10/01/18.
//  Copyright 2010 jiro music. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import "DataAnalyzeArg.h"
#import "../Common/DbOperator.h"
#import "../Common/DbInfo.h"
#import "../DbTypes/DbConstants.h"


enum DataAnalyzerErrorType
{
	
	DataAnalyzerError_DbConnection,					//	DBへの接続に失敗

	DataAnalyzerError_InvalidOperationToField,		//	フィールドに対する不正な操作
	
	DataAnalyzerError_FailtoExecuteSqlQuery,		//	SQLクエリの実行に失敗

	DataAnalyzerError_None,							//	エラーなし
};

@interface DataAnalyzer : NSObject {

	DbInfo* dbInfo;

	DbOperator* dbOperator;
	
	DataAnalyzerErrorType errorType;
	
	NSString* errorMessage;
}

- (id) initWithConnectionToDb: (NSString*) dbName ofHost: (NSString*) host asUser: (NSString*) userName andDbInfo: (DbInfo*) dbInfo_;

- (DbOperator*) dbOperator;
 
- (NSString*) errorMessage;

-(void) disconnect;

/// データ件数
- (BOOL) countOf:  (DataAnalyzeArg*) arg intoValue: (double*) value;

/// データ件数
- (BOOL) countOf: (DataAnalyzeArg*) arg1 arg: (DataAnalyzeArg*) arg2 andJoinFieldId: (int) joinFieldId intoValue: (double*) value;
 
///	平均
- (BOOL) averageOf: (DataAnalyzeArg*) arg intoValue: (double*) value;

///	分散
- (BOOL) varianceOf: (DataAnalyzeArg*) arg intoValue: (double*) value; 

///	標準偏差
- (BOOL) standardDeviationOf: (DataAnalyzeArg*) arg intoValue: (double*) value; 

///	共分散
- (BOOL) covarianceOf: (DataAnalyzeArg*) arg1 arg: (DataAnalyzeArg*) arg2 andJoinFieldId: (int) joinFieldId intoValue: (double*) value;

///	相関係数
- (BOOL) correlationCoefficientOf: (DataAnalyzeArg*) arg1 arg: (DataAnalyzeArg*) arg2 andJoinFieldId: (int) joinFieldId intoValue: (double*) value;

///	回帰係数
- (BOOL) regressionCoefficientOf: (DataAnalyzeArg*) arg1 arg: (DataAnalyzeArg*) arg2 andJoinFieldId: (int) joinFieldId intoValue: (double*) value;

///	切片
- (BOOL) intersectionOf:  (DataAnalyzeArg*) arg1 arg: (DataAnalyzeArg*) arg2 andJoinFieldId: (int) joinFieldId intoValue: (double*) value;

/*
/// 回帰による予測値
- (double) predictionByRegression: (NSString*) tableName columnName: (NSString*) column andWhereClause: (NSString*) whereClause;
*/
@end
